<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
	<title>Administracion Usuario - Contact Manager</title>
	<style type="text/css">
		body {
			font-family: sans-serif;
		}
		.data, .data td {
			border-collapse: collapse;
			border: 1px solid #aaa;
			margin: 2px;
			padding: 2px;
		}
		.data th {
			font-weight: bold;
			background-color: #5C82FF;
			color: white;
		}
		.data, .data table {
			width: 100%;
		}
	</style>
</head>
<body>

<h2>User Manager</h2>

<form:form method="post" action="add.html" commandName="user">

	<table>
	<tr>
		<td><form:label path="userName"><spring:message code="label.userName"/></form:label></td>
		<td><form:input path="userName" /></td> 
	</tr>
	<tr>
		<td><form:label path="pass"><spring:message code="label.pass"/></form:label></td>
		<td><form:input path="pass" /></td>
	</tr>
	<tr>
		<td><form:label path="nombre"><spring:message code="label.firstname"/></form:label></td>
		<td><form:input path="nombre" /></td> 
	</tr>
	<tr>
		<td><form:label path="apellido"><spring:message code="label.lastname"/></form:label></td>
		<td><form:input path="apellido" /></td>
	</tr>
	<tr>
		<td><form:label path="email"><spring:message code="label.email"/></form:label></td>
		<td><form:input path="email" /></td>
	</tr>
	<tr>
		<td><form:label path="telefono"><spring:message code="label.telephone"/></form:label></td>
		<td><form:input path="telefono" /></td>
	</tr>
	<tr>
		<td><form:label path="permiso"><spring:message code="label.permiso"/></form:label></td>
		<td>
			<form:select path="idPermiso">
				<form:option value="NONE" label="--- Select ---" />
				<form:options items="${permisos}" itemLabel="permiso" itemValue="id"/>
			</form:select>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<input type="submit" value="<spring:message code="label.addUser"/>"/>
		</td>
	</tr>
</table>	
</form:form>

	
<h3>Users</h3>
<c:if  test="${!empty userList}">
<table class="data">
<tr>
	<th>User Name</th>
	<th>Permiso</th>
	<th>Name</th>
	<th>Email</th>
	<th>Telephone</th>
	<th>&nbsp;</th>
</tr>
<c:forEach items="${userList}" var="user">
	<tr>
	 	<td>${user.userName} </td>
	 	<td>${user.permiso.permiso} </td>
		<td>${user.nombre}, ${user.apellido} </td>
		<td>${user.email}</td>
		<td>${user.telefono}</td>
		<td><a href="delete/${user.id}">delete</a></td>
	</tr>
</c:forEach>
</table>
</c:if>


</body>
</html>
